<template>
  <div class="login_cons">
    <el-row>
      <el-col :span="12" :xs="0"></el-col>
      <el-col :span="12" :xs="24">
        <el-form class="elform">
          <h1 class="h1">Hello</h1>
          <h2>欢迎来到硅谷甄选</h2>
          <el-form-item>
            <el-input
              :prefix-icon="User"
              v-model="loginForm.username"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-input
              type="password"
              v-model="loginForm.password"
              :show-password="true"
              :prefix-icon="Lock"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="but" class="el_bth">
              登录
            </el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>
<script setup lang="ts">
import { User, Lock } from '@element-plus/icons-vue'
import { reactive } from 'vue'
import { useCounterStore } from '@/stores/counter'
import { useRouter, useRoute } from 'vue-router'
import { ElNotification } from 'element-plus'
let loginForm = reactive({ username: '', password: '' })
let usest = useCounterStore()
let router = useRouter()
let Route = useRoute()
const but = async () => {
  try {
    await usest.userLogin(loginForm)
    let redirect: any = Route.query.red
    router.push({ path: redirect || '/' })
    ElNotification({
      type: 'success',
      message: '你好',
    })
  } catch (error) {
    ElNotification({
      type: 'error',
      message: (error as Error).message,
    })
  }
  try {
    await usest.userReqInfo()
  } catch (error) {
    ElNotification({
      type: 'error',
      message: (error as Error).message,
    })
  }
}
</script>
<style scoped lang="scss">
.login_cons {
  width: 100%;
  height: 100vh;
  background: url('@/assets/images/background.jpg') no-repeat;
  background-size: cover;
}
.elform {
  position: relative;
  width: 80%;

  top: 35vh;
  background: url('@/assets/images/login_form.png') no-repeat;
  background-size: cover;

  h1 {
    color: #ffffff;
    font-size: 40px;
  }
  h2 {
    color: #ffffff;
    font-size: 20px;
    margin: 20px 0px;
  }
  .el_bth {
    width: 100%;
  }
}
</style>
